package com.mx.nbainformation.biz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import com.mx.nbainformation.config.Constants;
import com.mx.nbainformation.util.FileUtil;
import com.mx.nbainformation.util.HttpUtil;

import android.content.Context;

public class BizVideo {
	public final static String TARGET="target";
	public final static String ITEM="item";
	private Context _context;
	public static String Result="";
	public BizVideo(Context context)
	{
		_context=context;
	}
	
	public List<List<Map<String, Object>>> getVideosList(String url) {
		List<List<Map<String,Object>>> list=new ArrayList<List<Map<String,Object>>>();
		List<Map<String,Object>> listDay=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> listWeek=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> listMonth=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> listSplendid=new ArrayList<Map<String,Object>>();
		list.add(listDay);
		list.add(listWeek);
		list.add(listMonth);
		list.add(listSplendid);
		Result=HttpUtil.doGet(url, _context);
		if(Result==null)
		{
			return null;
		}
		Matcher m=FileUtil.getPattern(Constants.VideosList, Result);
		
		for(int i=0;i<3;i++)
		{
			if(!m.find())break;
			String temp=m.group();
			Matcher mItem=FileUtil.getPattern(Constants.VideosItemUrl, temp);
			while(mItem.find())
			{
				String Item=mItem.group();
				String VideoUrl=Item.replaceAll(Constants.VideosItemUrlReplace1, "");
				VideoUrl=VideoUrl.replaceAll(Constants.VideosItemUrlReplace2, "");
				Matcher mVideoName =FileUtil.getPattern(Constants.VideoItemName, Item);
				mVideoName.find();
				String VideoName=mVideoName.group();
				VideoName=VideoName.replaceAll(Constants.VideoItemNameReplace1, "");
				VideoName=VideoName.replaceAll(Constants.VideoItemNameReplace2, "");
				Map<String,Object> map=new HashMap<String, Object>();
				map.put(TARGET, VideoUrl);
				map.put(ITEM, VideoName);
				switch(i)
				{
				case 0:
					listDay.add(map);
					break;
				case 1:
					listWeek.add(map);
					break;
				case 2:
					listMonth.add(map);
					break;
				}
			}
		}
//		listSplendid
		Matcher mS=FileUtil.getPattern(Constants.VideoSplendidList, Result);
		if(!mS.find())return list;
		String Splendid=mS.group();
		Matcher SItems=FileUtil.getPattern(Constants.VideoSplendidItem, Splendid);
		while(SItems.find())
		{
			String item=SItems.group();
			item=item.replaceAll(Constants.VideoSplendidItemReplace1, "");
			item=item.replaceAll(Constants.VideoSplendidItemReplace2_toaaabbb, "aaabbb");
			item=item.replaceAll(Constants.VideoSplendidItemReplace3, "");
			Map<String,Object> map=new HashMap<String, Object>();
			String[] temp=item.split("aaabbb");
			map.put(TARGET, temp[0]);
			map.put(ITEM, temp[1]);
			listSplendid.add(map);
		}
		return list;
	}
}
